package com.goods.controller.business;

import com.goods.business.service.InStockServices;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.InStockVO;
import com.goods.common.vo.system.PageVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @author ：MJS
 * @date ：Created in 2021/6/8  22:52
 * @description：TODO
 */
@Api(tags = "业务管理-入库管理")
@RestController
@RequestMapping("/business/inStock")
public class InStockController {
    @Autowired
    private InStockServices inStockServices;
    //加载入库表格数据
    @ApiOperation(value = "入库信息列表", notes = "模糊查询入库信息列表")
    @GetMapping("/findInStockList")
    public ResponseBean<PageVO<InStockVO>> findInStockList(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                            @RequestParam(value = "pageSize",defaultValue = "6") Integer pageSize,
                                                            InStockVO inStockVO){
        PageVO<InStockVO>inStockList=inStockServices.findInStockList(pageNum,pageSize,inStockVO);
        return ResponseBean.success(inStockList);
    }
    //查询明细
    @ApiOperation(value = "入库信息列表中的明细", notes = "查询入库信息选中的明细信息")
    @GetMapping("/detail/{id}")
    public ResponseBean<Map<String,Object>> detail(@PathVariable Long id,
                                    @RequestParam Integer pageNum){
            Map<String, Object> map = new HashMap<>();
            InStockVO inStockVO=inStockServices.detail(id,pageNum);
            map.put("itemVOS", inStockVO.getProducts());
            map.put("total", inStockVO.getProducts().size());
            map.put("supplierVO", inStockVO);
            map.put("status", inStockVO.getStatus());
            return ResponseBean.success(map);
    }
    //移入回收站
    @ApiOperation(value = "移入回收站", notes = "数据移入回收站")
    @PutMapping("/remove/{id}")
    public ResponseBean remove(@PathVariable Long id){
        inStockServices.remove(id);
        return ResponseBean.success();
    }
    //从回收站恢复
    @ApiOperation(value = "从回收站恢复", notes = "数据移出回收站")
    @PutMapping("/back/{id}")
    public ResponseBean back(@PathVariable Long id){
        inStockServices.back(id);
        return ResponseBean.success();
    }
    //删除物资
    @ApiOperation(value = "从回收站删除", notes = "删除物资")
    @DeleteMapping("/delete/{id}")
    public ResponseBean delete(@PathVariable Long id){
        inStockServices.delete(id);
        return ResponseBean.success();
    }

    //添加入库单
    @ApiOperation(value = "添加入库单", notes = "入库单的添加")
    @PostMapping("/addIntoStock")
    public ResponseBean addStock( @RequestBody InStockVO inStockVO){
        inStockServices.addStock(inStockVO);
        return ResponseBean.success();
    }
    //入库单审核
    @ApiOperation(value = "入库单审核", notes = "入库单审核")
    @PutMapping("/publish/{id}")
    public ResponseBean publish(@PathVariable Long id){
        inStockServices.publish(id);
        return ResponseBean.success();
    }
}
